package MyThread;

public class ThreadSecurity extends Thread {
    private static Object object = new Object();

    @Override
    public void run() {
        sum();
    }

    public synchronized void sum() {
        synchronized (object) {
            for (int i = 0; i < 10000; i++) {
                sum++;
            }
        }
    }

    public static int sum = 0;

    public static void main(String[] args) throws InterruptedException {
        ThreadSecurity t1 = new ThreadSecurity();
        ThreadSecurity t2 = new ThreadSecurity();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(sum);

    }


}
